<div class="modal-content">

    <div class="modal-header">
        创建订单
    </div>

    <div class="modal-body clearfix">
        <!-- 电话、姓名、性别 -->
        <div class="col-md-12 form-group">
            <div class=col-md-4>
                <input type="text" class="form-control hidden" id="uid" value="{{ user.id }}">
                <input type="text" class="form-control hidden" id="draft_demand_id" value="{{ draft_demand_id }}">
                <input type="text" class="form-control" id="mobile" value="{{ user.mobile | encrypt }}">
            </div>
            <div class=col-md-4>
                <input type="text" class="form-control" id="nickname" value="{{ user.nickname }}">
            </div>
            <div class=col-md-4>
                <select class="form-control" id="gender" name="gender">
                    {% for choice in gender_choice %}
                        <option {% if choice[0]==user.gender %}selected{% endif %} value="{{ choice[0] }}">{{ choice[1] }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>

        <!-- 省份、城市 -->
        <div class="col-md-12 form-group">
            <div class=col-md-4>
                <select class="form-control" id="prov" name="prov">
                    {% for choice in prov_choice %}
                        <option {% if choice[0]==user.prov %}selected{% endif %} value="{{ choice[0] }}">{{ choice[1] }}</option>
                    {% endfor %}
                </select>
            </div>
            <div class=col-md-4>
                <select class="form-control" id="city" name="city">
                    {% for choice in city_choice %}
                        <option {% if choice[0]==user.city %}selected{% endif %} value="{{ choice[0] }}">{{ choice[1] }}</option>
                    {% endfor %}
                </select>
            </div>
        </div>

        <!-- 详细地址 -->
        <div class="col-md-12 form-group">
            <div class=col-md-12>
                <input type="text" class="form-control" id="addr" placeholder="详细地址">
            </div>
        </div>

        <!-- 订单类型 -->
        <div class="col-md-12 form-group">
            <div class=col-md-12>
                <div class="btn-group" data-toggle="buttons">
                    {% for cate in cate_choice %}
                        <label class="btn btn-primary {% if cate[0]==draft_demand_cate%}active{% endif %}" for="cateOption{{loop.index}}">
                            <input type="radio" name="cate" value="{{cate[0]}}" id="cateOption{{loop.index}}" autocomplete="off" {% if cate[0]==draft_demand_cate%}checked{% endif %}>{{cate[1]}}
                        </label>
                    {% endfor %}
                </div>
            </div>
        </div>

    </div>

    <div class="modal-footer">
        <!-- 上一步与下一步按钮 -->
        <div class="col-md-12 form-group">
            <div class="col-md-6">
                <button class="btn btn-default btn-block" data-dismiss="modal" aria-label="Close" id="goto_customer_modal">上一步</button>
            </div>
            <div class="col-md-6">
                <button class="btn btn-success btn-block" data-dismiss="modal" aria-label="Close" id="goto_demand_modal">下一步</button>
            </div>
        </div>
    </div>

</div>

<script type="text/javascript">
    // 省份与城市联动
    function get_city_choices(){
        var prov_name = $("#prov").val();
        if(prov_name != -1) {
            $.ajax({
                url: "{{ url_for('op_bp.ajax_get_cities') }}" + "?prov_name=" + encodeURI(prov_name),
                cache: true
            }).done(function (data) {
                $("#city").empty();
                for (var i = 0; i < data["choices"].length; i++) {
                    var id = data["choices"][i]["id"];
                    var name = data["choices"][i]["name"];
                    $("#city").append(
                        "<option value='" + id + "'>" + name + "</option>"
                    );
                }
                if(demand_info.city){
                    $('#city').val(demand_info.city)
                }
            }).fail(function () {
                alert("获取城市列表失败，请联系系统管理员!")
            });
        }
    }
    $("#prov").change(function (){
        get_city_choices();
    });

    // 上一步按钮触发事件
    function goto_customer_modal_event() {
        // 返回customer-modal模态框
        show_customer_modal();
    }
    $('#goto_customer_modal').click(function (){
        console.log('点击了上一步按钮');
        goto_customer_modal_event();
    });

    function fill_demand_info(){
        if(demand_info.demand_type){
            $('input:radio[name="demand_type"]').each(function(){
                this.checked = false;
                remove_active_label(this.id);
            });

            var t = $('input:radio[name="demand_type"][value="' + demand_info.demand_type + '"]');
            t[0].checked = true;
            add_active_label(t[0].id)
        }
        if(demand_info.demand_surr){
            $('input:radio[name="demand_surr"]').each(function(){
                this.checked = false;
                remove_active_label(this.id);
            });
            var s = $('input:radio[name="demand_surr"][value="' + demand_info.demand_surr + '"]');
            s[0].checked = true;
            add_active_label(s[0].id)
        }
        if(demand_info.demand_color){
            $('input:radio[name="demand_color"]').each(function(){
                this.checked = false;
                remove_active_label(this.id);
            });
            var c = $('input:radio[name="demand_color"][value="' + demand_info.demand_color + '"]');
            c[0].checked = true;
            add_active_label(c[0].id)
        }
        if(demand_info.demand_malf){
            $('input:radio[name="demand_malf"]').each(function(){
                this.checked = false;
                remove_active_label(this.id);
            });
            var m = $('input:radio[name="demand_malf"][value="' + demand_info.demand_malf + '"]');
            m[0].checked = true;
            add_active_label(m[0].id)
        }
        if(demand_info.demand_audio_sensitive){
            $('input:radio[name="demand_audio_sensitive"]').each(function(){
                this.checked = false;
                remove_active_label(this.id);
            });
            var sensitive = $('input:radio[name="demand_audio_sensitive"][value="' + demand_info.demand_audio_sensitive + '"]');
            this.checked = true;
            add_active_label(sensitive[0].id)
        }
        if(demand_info.demand_span){
            $('#demand_span').val(demand_info.demand_span)
        }
        if(demand_info.demand_size){
            $('#demand_size').val(demand_info.demand_size)
        }
        if(demand_info.demand_budget){
            $('#demand_budget').val(demand_info.demand_budget)
        }
        if(demand_info.demand_remark){
            $('#demand_remark').val(demand_info.demand_remark)
        }
        if(demand_info.demand_admin_remark){
            $('#demand_admin_remark').val(demand_info.demand_admin_remark)
        }
    }

    // 下一步按钮触发事件
    function goto_demand_modal_event() {
        show_demand_modal();
    }
    $('#goto_demand_modal').click(function (){
        console.log('点击了下一步按钮');
        goto_demand_modal_event();
    });

</script>
